//---------------------------------------------------------------------------
#ifndef CDateH
#define CDateH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include "CEdit.h"
#include <StdCtrls.hpp>
#include "CtrlStd.h"
#include "Dates.h"
#include "uDates.h" //Pour DATE_MAX_ANNEES2000


#define ANNEE_MIN          1200
#define ANNEE_MAX          2030

enum FormatsDate {    eJJMMAA=0, eJJMMAAAA, eJJMMAAA,
               eJJMM,
               eMMAA, eMMAAAA, eMMAAA,
               eJJ,
               eMM,
               eAA, eAAAA, eAAA,
               };



class PACKAGE_CTRLSTD CDate : public CCustomEdit
   {
   private:
      typedef CCustomEdit inherited; //Pour que les lignes de types inherited::Text fassent référence à CCustomEdit::Text
      short int      FJour;
      short int      FMois;
      short int      FAnnee;
      bool           FAujourdhui;
      FormatsDate    FDateFormats;
      sDate          FDateStruct;
      bool           FbDateValid;
      TNotifyEvent   FOnDateInvalide;
      short          FSeuilAnnees2000;

   __published:
      __property Anchors;
      __property Alignment;
      __property AutoSelect;
      __property AutoSize;
      __property BorderStyle;
      __property Color;
      __property CharCase;
      __property Ctl3D;
      __property DragCursor;
      __property DragMode;
      __property Enabled;
      __property Font;
      __property HelpContext;
      __property Hint;
      __property Libelle;
      __property LibelleFont;
      __property MaxLength = {stored = false}; //Pas utilisé => C'est DateFormats qui délimite la longueur.
      __property Modified;
      __property OEMConvert;
      __property ParentFont;
      __property ParentShowHint;
      __property PasswordChar;
      __property PopupMenu;
      __property ReadOnly;
      __property ShowHint;
      __property SizeEspace;
      __property TabOrder;
      __property TabStop;
      __property Visible;

      __property short int    Annee           = { read=FAnnee,           write=SetAnnee          };
      __property bool         Aujourdhui      = { read=FAujourdhui,      write=SetAujourdhui     };
      __property FormatsDate  DateFormats     = { read=FDateFormats,     write=SetDateFormats, default=eJJMMAAA };
      __property AnsiString   DateString      = { read=GetDateString,    write=SetDateString     };
      __property short int    Jour            = { read=FJour,            write=SetJour           };
      __property short int    Mois            = { read=FMois,            write=SetMois           };
      __property AnsiString   Text            = { read=GetDateString,    write=SetDateString, stored = false}; //Idem que DateString
      __property short int    SeuilAnnees2000 = { read=FSeuilAnnees2000, write=SetSeuilAnnees2000, default=DATE_MAX_ANNEES2000};

      // Publication des événements hérités
      __property OnChange;
      __property OnStartDrag;
      __property OnDragDrop;
      __property OnDragOver;
      __property OnEndDrag;
      __property OnIllegalChar;
      __property OnIllegalPaste;
      __property OnKeyDown;
      __property OnKeyPress;
      __property OnKeyUp;
      __property OnEnter;
      __property OnExit;
      __property OnMouseDown;
      __property OnMouseMove;
      __property OnMouseUp;
      __property OnClick;
      __property OnDblClick;

      __property TNotifyEvent OnDateInvalide = {read=FOnDateInvalide, write=FOnDateInvalide};


   public:
      __property bool         DateEmpty       = { read=IsDateEmpty};
      __property bool         DateValid       = { read=IsDateValid};
      __property TDateTime    Date            = { read=GetDate,            write=SetTDTDate           };
      __property sDate        DateStruct      = { read=FDateStruct,        write=SetDateStruct        };

   protected:
      DYNAMIC void __fastcall KeyPress( char &Key );
      DYNAMIC void __fastcall KeyDown( Word &Key, Classes::TShiftState Shift);
      void __fastcall WndProc( TMessage &Message );

   private:
      void        __fastcall SetAnnee(        short int   aAnnee          );
      void        __fastcall SetAujourdhui(   bool        bAujourdhui     );
      void        __fastcall SetJour(         short int   shiJour         );
      void        __fastcall SetMois(         short int   shiMois         );
      void        __fastcall SetTDTDate(      TDateTime TDTDate           );
      void        __fastcall SetDateFormats(  FormatsDate FDDateFormats   );
      AnsiString  __fastcall GetDateString();
      void        __fastcall SetDateString(const AnsiString aDateString);
      void        __fastcall SetDateStruct(   const sDate &DDateStruct    );
      void        __fastcall SetSeuilAnnees2000 (short int shSeuilAnnees2000);

      TDateTime   __fastcall GetDate() const;
      AnsiString  __fastcall GetFormatString() const;
      short int   __fastcall GetJoursParMois() const;

      bool      __fastcall IsDateValid() /*const*/;
      bool      __fastcall IsDateEmpty() /*const*/;
      bool        __fastcall IsAnnee4DigitsValid( const AnsiString &aA ) const;
      AnsiString  __fastcall MakeText( char &Key );
      short int   __fastcall Conv2DigitsTo4( short int shiAnnee ) const;
      AnsiString __fastcall FormaterText();

   public:
      __fastcall CDate(TComponent* Owner);
      virtual __fastcall ~CDate(){};
   };


#include <CForm.h>
extern PACKAGE_CTRLSTD void __fastcall DDX_Date(        CDataExchange* pdx, CDate*       pEdDate, TDateTime& date);
//---------------------------------------------------------------------------
#endif
